package com.study.行为型模式.迭代器模式;

import java.util.ArrayList;
import java.util.Iterator;

public class PrintInfo {

    //学院集合
    ArrayList<College> colleges;

    public PrintInfo(ArrayList<College> colleges) {
        this.colleges = colleges;
    }
    //遍历学院，调用printDepartment输出各个系
    public void printCollege(){
        Iterator<College> iterator = colleges.iterator();
        while (iterator.hasNext()){
            College c = iterator.next();
            System.out.println("====="+c.getName()+"======");
            printDepartment(c.createIterator());
        }
    }

    //打印系
    public void printDepartment(Iterator iterator){

        while (iterator.hasNext()){
            Department d = (Department) iterator.next();
            System.out.println(d.getName());
        }
    }
}
